package jtg.optimizer;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class ConstraintSolverOptimizer {
//    private static final String isNegative = "^-\\d+$";
    // 编译正则表达式
    private static Pattern pattern1 = Pattern.compile("^-\\d+(\\.\\d+)?$");
    private static Pattern pattern2 = Pattern.compile("[-+]?[0-9]*\\.?[0-9]+([eE][-+]?[0-9]+)?");
    /**@param s 要检查的字符串
     * @return 如果输入的s对应的是一个负数，那么，将负数转为：0-数字
     * */
    public static String negativeOptimizer(String s){
        String[] list = s.split(" ");
        String result = "";
        for (String item : list){
            Matcher matcher = pattern1.matcher(item);
            if (matcher.find())
                result = result+" "+"(0"+item+")";
            else result = result+" "+item;
        }
        return result.trim();
    }

    public static String optimizer(String s){
        String[] list = s.split(" ");
        String result = "";
        for (String item : list){
            Matcher matcher1 = pattern1.matcher(item);
            if (matcher1.find())
                result = result+" "+"(0"+item+")";
            else result = result+" "+item;
        }
        return result.trim();
    }

    public static void main(String[] args) {
        System.out.println(negativeOptimizer("i0 cmp -0.8"));
    }
}
